package org.monkey.example.pay.controller;

import io.swagger.annotations.Api;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.monkey.common.constant.entity.ErrorResultEnum;
import org.monkey.common.constant.entity.Result;
import org.monkey.common.constant.exception.BaseException;
import org.monkey.example.pay.entity.form.PayForm;
import org.monkey.example.pay.service.UserAmountService;
import org.monkey.request.plugin.entity.TimeAnalyse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Data
@RestController
@Api(value = "/payApi", tags = "支付接口")
@RequestMapping("/payApi")
public class PayController {

  @Value("${payChinese}")
  private String payChinese;
  @Value("${payEnglish}")
  private String payEnglish;
  @Autowired
  UserAmountService userAmountServiceImpl;

  @TimeAnalyse
  @GetMapping("/payError")
  public Result<String> testPayError() {
    throw new BaseException(ErrorResultEnum.TEST_ERROR);
  }

  @TimeAnalyse
  @GetMapping
  public Result<String> pay() {
    return Result.success(getPayChinese() + ":" + getPayEnglish());
  }

  @TimeAnalyse
  @PostMapping
  public Result<Boolean> payAmount(@RequestBody PayForm payForm) {
    return Result.success(userAmountServiceImpl.amountReduce(payForm));
  }
}
